<?php

use Illuminate\Support\Str;
use Illuminate\Support\Facades\Storage;


/**
 * 获取完整URL
 * @param string $value
 * @param string $disk
 * @return string
 */
function getFullUrlDomain(string $value, string $disk = 'public'): string
{
    if (blank($value)) {
        return $value;
    }
    // 判断字段是否以http://或https://开头
    if (Str::startsWith($value, ['http://', 'https://'])) {
        return $value;
    }
    return Storage::disk($disk)->url($value);
}


/**
 * 获取随机字符串
 * @param int $length
 * @return string
 */
function generateRandomString(int $length = 10): string
{
    $characters   = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';

    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, strlen($characters) - 1)];
    }

    return $randomString;
}

